package com.ytjj.qmyx.mall.config;

import com.github.wxpay.sdk.WXPayConfig;
import com.ytjj.qmyx.mall.model.PayConfig;
import lombok.ToString;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 *
 * @version 1.0
 *
 */
@ToString
public class MyWxConfig implements WXPayConfig {

    private PayConfig payConfig;


    public MyWxConfig(PayConfig payConfig){
        this.payConfig = payConfig;
    }
    @Override
    public String getAppID() {
        return payConfig.getAppid();
    }

    @Override
    public String getMchID() {
        return payConfig.getMchId();
    }

    @Override
    public String getKey() {
        return payConfig.getWxKey();
    }

    @Override
    public InputStream getCertStream() {
        File file = new File(payConfig.getCertPath());
        try{
            InputStream certStream = new FileInputStream(file);
            byte[] certData = new byte[(int) file.length()];
            certStream.read(certData);
            certStream.close();
            ByteArrayInputStream certBis = new ByteArrayInputStream(certData);
            return certBis;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 0;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 0;
    }
}
